package com.example.myapplication.tack_20;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.myapplication.R;
import com.example.myapplication.tack_20.fragment.NewsFragment;
import com.example.myapplication.tack_20.fragment.PersonFragment;
import com.example.myapplication.tack_20.fragment.ServletFragment;
import com.google.android.material.bottomnavigation.BottomNavigationView;

public class VolunteerActivity extends AppCompatActivity {
    private ImageView exit;
    private LinearLayout line;
    private NewsFragment newsFragment;
    private ServletFragment servletFragment;
    private PersonFragment personFragment;
    private BottomNavigationView bottom;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_20_activity_volunteer);
        init();
        exit_();
        getSupportFragmentManager().beginTransaction().replace(R.id.line,newsFragment).commit();
        bottom.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch(item.getItemId()){
                    case R.id.news:
                        getSupportFragmentManager().beginTransaction().replace(R.id.line,newsFragment).commit();
                        break;
                    case R.id.person:
                        getSupportFragmentManager().beginTransaction().replace(R.id.line,personFragment).commit();
                        break;
                    case R.id.servlet:
                        getSupportFragmentManager().beginTransaction().replace(R.id.line,servletFragment).commit();
                        break;
                }

                return true;
            }
        });

    }

    private void init() {
        exit = findViewById(R.id.exit);
        newsFragment = new NewsFragment();
        servletFragment = new ServletFragment();
        personFragment = new PersonFragment();
        bottom = findViewById(R.id.bottom);
        line = findViewById(R.id.line);
    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                VolunteerActivity.this.finish();
            }
        });
    }
}